package rs.pnv.model.insurance;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.NotBlank;

import rs.pnv.model.AbstractEntity;

@Entity
@Table(name = "SEP_OWNER")
@XmlAccessorType(XmlAccessType.FIELD)
public class Owner extends AbstractEntity {

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String ownerFirstname;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String ownerLastname;

	@NotBlank
	@Column(nullable = false, unique = true)
	@XmlElement(nillable = false)
	private String ownerJmbg;

	@OneToOne(optional = true)
	private Home home;

	@OneToOne(optional = true)
	private Vehicle vehicle;

	public Owner() {

	}

	public String getOwnerFirstname() {
		return ownerFirstname;
	}

	public void setOwnerFirstname(String ownerFirstname) {
		this.ownerFirstname = ownerFirstname;
	}

	public String getOwnerLastname() {
		return ownerLastname;
	}

	public void setOwnerLastname(String ownerLastname) {
		this.ownerLastname = ownerLastname;
	}

	public String getOwnerJmbg() {
		return ownerJmbg;
	}

	public void setOwnerJmbg(String ownerJmbg) {
		this.ownerJmbg = ownerJmbg;
	}

	public Home getHome() {
		return home;
	}

	public void setHome(Home home) {
		this.home = home;
	}

	public Vehicle getVehicle() {
		return vehicle;
	}

	public void setVehicle(Vehicle vehicle) {
		this.vehicle = vehicle;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(ownerFirstname)
				.append(ownerLastname)
				.append(ownerJmbg)
				.appendSuper(super.hashCode())
				.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}

		final Owner otherOwner = (Owner) obj;

		return new EqualsBuilder()
				.append(ownerFirstname, otherOwner.getOwnerFirstname())
				.append(ownerLastname, otherOwner.getOwnerLastname())
				.append(ownerJmbg, otherOwner.getOwnerJmbg())
				.appendSuper(super.equals(obj))
				.isEquals();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("ownerFirstname", ownerFirstname)
				.append("ownerLastname", ownerLastname)
				.append("ownerJmbg", ownerJmbg)
				.append(super.toString())
				.toString();
	}

}
